/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014-7-15         luwei
 */

package com.tianci.appstore.ui.search;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.View;

import com.coocaa.app.gamecenter.pages.detail.DetailActivity;
import com.coocaa.app.gamecenter.pages.search.GameSearchActivity;
import com.coocaa.x.app.framework.app.LiteAppApplication;
import com.coocaa.x.framework.utils.LogUtils;
import com.skyworth.framework.skysdk.ipc.SkyStartActivity;
import com.tianci.appstore.AppDetailActivity;
import com.tianci.appstore.R;
import com.tianci.appstore.SearchActivity;
import com.tianci.appstore.ui.SkinManager;
import com.tianci.appstore.ui.data.SkyAppBaseData;
import com.tianci.appstore.ui.widget.AlwaysMarqueeTextView;
import com.tianci.appstore.ui.widget.SkyBaseItemView;
import com.tianci.appstore.ui.widget.TipToast;
import com.tianci.appstore.utils.SkyConstants;

import java.util.HashMap;
import java.util.Map;

public class SearchHotItem extends SkyBaseItemView {
    public SearchHotItem(Context context) {
        super(context);
        SkinManager.setBackground(this, R.drawable.search_block_selector);
        this.setPadding(SkyConstants.shadowWidth, SkyConstants.shadowWidth,
                SkyConstants.shadowWidth, SkyConstants.shadowWidth);
        createView();
    }

    @Override
    protected void createView() {
        titleText = new AlwaysMarqueeTextView(mContext);
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        addView(titleText, params);

        titleText.setPadding(SkyConstants.Div(40), 0, SkyConstants.Div(40), 0);
        titleText.setGravity(Gravity.CENTER_VERTICAL);
        titleText.setTextColor(Color.WHITE);
        titleText.setTextSize(SkyConstants.Dpi(36));
    }

    @Override
    public void update(SkyAppBaseData data) {
        this.data = data;
        titleText.setText(data.getTitle());
    }

    @Override
    protected void refreshImage(String url, Bitmap result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onClick(View v) {
        if (!LiteAppApplication.checkNetworkConnection(TipToast.showNetIsNotConnectedToastRunnable) || data == null)
            return;
        LogUtils.d("detail", "onClick, data = " + data.toString());
        if (data.isGame()) {
            // Intent intent = new Intent("com.coocaa.gamecenter.detail");
            // intent.putExtra(DetailActivity.INTENT_APPID_KEY, data.getId());
            // mContext.startActivity(intent);

            LogUtils.d("id", data.getId());
            // LogUtils.d("id", data.get);
            Intent intent = new Intent("com.coocaa.gamecenter.detail");
            int appid = -1;
            try {
                appid = Integer.valueOf(data.getId());
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            intent.putExtra(DetailActivity.INTENT_APPID_KEY, appid);
            // intent.putExtra(DetailActivity.INTENT_PACKAGENAME_KEY, mAppData.getPkgName());
//            mContext.startActivity(intent);
            HashMap<String,String> map = new HashMap<String,String>();
            map.put("search_key","hot_item"); 
            SkyStartActivity.startActivity(mContext, mContext.getClass().getName(), intent, map, false);
            Map<String,String> params = new HashMap<String, String>();
            params.put("id","应用-" + (mIndex + 1));
            params.put("block_content_name",data.getTitle());
            params.put("block_content_id",data.getPackageName());
            LogUtils.submit(LogUtils.PRODUCTID_APPSTORE, "gc2_search_recommend_onclick", params);
        } else {
            Intent intent = new Intent(mContext, AppDetailActivity.class);
            intent.putExtra("id", this.data.getId());
            intent.putExtra("pkgName", "PPPPPPPPP");
//            mContext.startActivity(intent);
            HashMap<String,String> map = new HashMap<String,String>();
            map.put("search_key","hot_item");
            SkyStartActivity.startActivity(mContext, mContext.getClass().getName(), intent, map, false);
        }
    }

    @Override
    public void destory() {
        // TODO Auto-generated method stub

    }
}
